package org.smile.jstl.tags.pager;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
/**
 * 每页显示长度标签
 * @author strive
 */
public class SizesTag extends PageTagSupport {
	
	private String list="15,30,50,100";
	private String id;
	private String style;
	private String css;
	
	public int doStartTag() throws JspException {
		super.doStartTag();
		JspWriter writer = pageContext.getOut(); 
		String[] sizeList=list.split(",");
		StringBuffer sb=new StringBuffer();
		int currentSize=pagerTag.getMaxPageItems();
		try{
			sb.append("<select ").append(id==null?"":"id=\""+id+"\" ");
			sb.append(style==null?"":"style=\""+style+"\" ");
			sb.append(css==null?"":"class=\""+css+"\" " );
			sb.append(" onchange=\"window.location.href=this.options[this.selectedIndex].value\">");
			for(int i=0;i<sizeList.length;i++){
				sb.append("<option ");
				if(sizeList[i].equals(Integer.toString(currentSize))){
					sb.append(" selected ");
				}
				sb.append(" value=\"").append(pagerTag.getSizeUrl(0, sizeList[i])).append("\">").append(sizeList[i]).append("</option>");
				
			}
			sb.append("</select>");
			writer.println(sb);
		}catch(Exception e){
			throw new JspException("pager tag case a exception :",e);
		}
		return EVAL_BODY_INCLUDE;
	}

	public void release() {
		super.release();
	}

	public String getList() {
		return list;
	}

	public void setList(String list) {
		this.list = list;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getCss() {
		return css;
	}

	public void setCss(String css) {
		this.css = css;
	}
}
